package com.ruoyi.dynamic.controller.app;

import com.ruoyi.common.core.annotation.valid.group.ValidGroup;
import com.ruoyi.common.core.constant.constant.PathConstant;
import com.ruoyi.common.core.context.SecurityContextHolder;
import com.ruoyi.common.core.pojo.result.Pages;
import com.ruoyi.common.core.pojo.vo.BaseVO;
import com.ruoyi.common.core.pojo.vo.PageVO;
import com.ruoyi.common.core.result.Result;
import com.ruoyi.dynamic.model.pojo.entity.RoomSing;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomSingAddRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomSingDelRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomSingSearchRequest;
import com.ruoyi.dynamic.service.IRoomSingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;


@Tag(name = "App-房间KTV相关", description = "App-房间KTV相关")
@RestController
@RequestMapping(PathConstant.APP_PATH + "room-sing")
public class AppRoomSingController {


    private final IRoomSingService iRoomSingService;
    public AppRoomSingController(IRoomSingService iRoomSingService) {
        this.iRoomSingService = iRoomSingService;
    }


    @Operation(summary = "点歌列表", description = "点歌列表")
    @GetMapping("listPage")
    public PageVO<RoomSing> listPage(@ParameterObject @Valid AppRoomSingSearchRequest request) {
        Pages<RoomSing> roomSingPages = iRoomSingService.listPage(request);
        return Result.page(roomSingPages);
    }

    @Operation(summary = "点歌", description = "点歌")
    @PostMapping("add")
    public BaseVO add(@RequestBody @Validated(ValidGroup.Insert.class) AppRoomSingAddRequest request) {
        boolean add = iRoomSingService.add(request, SecurityContextHolder.getUserId());
        return Result.successOrFail(add);
    }

    @Operation(summary = "删除点歌", description = "删除点歌")
    @PostMapping("remove")
    public BaseVO remove(@RequestBody @Validated AppRoomSingDelRequest request) {
        boolean remove = iRoomSingService.removeSing(request, SecurityContextHolder.getUserId());
        return Result.successOrFail(remove);
    }

    @Operation(summary = "置顶点歌", description = "置顶点歌")
    @PostMapping("top")
    public BaseVO top(@RequestBody @Validated AppRoomSingDelRequest request) {
        boolean remove = iRoomSingService.topSing(request, SecurityContextHolder.getUserId());
        return Result.successOrFail(remove);
    }

    @Operation(summary = "播放音乐", description = "播放音乐")
    @PostMapping("play")
    public BaseVO play(@RequestBody @Validated AppRoomSingDelRequest request) {
        boolean add = iRoomSingService.playSing(request, SecurityContextHolder.getUserId());
        return Result.successOrFail(add);
    }

    @Operation(summary = "暂停音乐", description = "暂停音乐")
    @PostMapping("stop")
    public BaseVO stop(@RequestBody @Validated AppRoomSingDelRequest request) {
        boolean add = iRoomSingService.stopSing(request, SecurityContextHolder.getUserId());
        return Result.successOrFail(add);
    }
}
